﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using ZX.DAL.DBExtend;
using DevExpress.Web.ASPxGridView;

namespace ZX.WebApp.Crm.Report
{
    public partial class RptAllCustomerInfo : BasePage
    {
        BTCrmCustomer bll = new BTCrmCustomer();
        DbSql db = new DbSql();
        string strEntity = string.Empty;
        string strOrder = string.Empty;
        string strCondition = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            strEntity = this.GetStringFromQueryString("entity", "");
            strOrder = this.GetStringFromQueryString("order", "");
            strCondition = this.GetStringFromQueryString("condition", "");
            if (strCondition == "")
            {
                strCondition = string.Format(" CustomUser='{0}' and IsValue='1'", this.UserId.ToString());
            }
            if (!this.IsPostBack)
            {
                this.ASPxPager1.ItemCount = db.GetRowCount(strEntity, strCondition);
                GetData(this.ASPxPager1.ItemsPerPage, 0, strEntity, strOrder, strCondition);
            }
            else
            {
                gvAllCustomerInfo.DataSource = this.Session["data"];
                gvAllCustomerInfo.DataBind();
            }
        }
        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strCustomerName = this.txtCustomerName.Value.Trim();
            if (strCustomerName != "")
            {
                strCondition += " and CustomerName like '%" + strCustomerName + "%'";
            }
            this.ASPxPager1.ItemCount = db.GetRowCount(strEntity, strCondition);
            GetData(this.ASPxPager1.ItemsPerPage, 0, strEntity, strOrder, strCondition);
        }
        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ASPxPager1_PageIndexChanged(object sender, EventArgs e)
        {
            GetData(this.ASPxPager1.ItemsPerPage, this.ASPxPager1.PageIndex, strEntity, strOrder, strCondition);
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="_PageSiez"></param>
        /// <param name="_PageIndex"></param>
        /// <param name="strEntity"></param>
        /// <param name="strOrder"></param>
        /// <param name="strCondition"></param>
        protected void GetData(int _PageSiez, int _PageIndex, string strEntity, string strOrder, string strCondition)
        {
            DataSet ds = bll.GetAllCustomerInfoRpt(_PageSiez, _PageIndex, strEntity, strOrder, strCondition);
            this.Session["data"] = ds.Tables[0];
            this.gvAllCustomerInfo.DataSource = ds.Tables[0];
            this.gvAllCustomerInfo.DataBind();
        }

        protected void LinkManGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["CustomerId1"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void CenterRecordGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["CustomerId2"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void WorkRecordGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["CustomerId3"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void OrderGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["CustomerId4"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void PayGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["OrderProductId1"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void TeacherGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["CustomerId6"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void DeliverGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["OrderProductId2"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void TrainGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["OrderProductId3"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void ProjectGrid_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["OrderProductId4"] = gridView.GetMasterRowKeyValue().ToString();
        }
        protected void OrderProduct_DataSelect(object sender, EventArgs e)
        {
            ASPxGridView gridView = sender as ASPxGridView;
            Session["OrderId"] = gridView.GetMasterRowKeyValue().ToString();
        }
    }
}